package brightgrove.applogic2;

import brightgrove.applogic.FilmHelper;
import brightgrove.model.Film;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.util.ArrayList;
import java.util.List;

public class FilmHelper2 extends DriverBasedHelper implements FilmHelper {
  List<String> filmList = new ArrayList<String>();
    
  public FilmHelper2(ApplicationManager2 manager) {
    super(manager.getWebDriver());
  }

  @Override
  public void create(Film film) {
      pages.userHomePage.ensurePageLoaded().clickAddButton();
      pages.addMoviePage.ensurePageLoaded().setTitle(film.getTitle()).setYear(film.getYear()).saveMovie();
  }

    @Override
    public boolean isFilmCreated() {
        if (pages.movieDetailPage.getEditButton().isDisplayed()) {
            return true;
        }
        else return false;
    }

    @Override
  public void delete(Film film) {
        pages.userHomePage.ensurePageLoaded().clickFilm(film.getTitle());
        pages.movieDetailPage.ensurePageLoaded().getRemoveButton().click();
        wait.until(ExpectedConditions.alertIsPresent()).accept();
  }

    @Override
    public boolean isFilmDeleted() {
        if (pages.userHomePage.ensurePageLoaded().getAddButton().isDisplayed()) {
            return true;
        } else return false;
    }

    @Override
  public List<Film> search(String title) {
//    pages.userHomePage.ensurePageLoaded().enterToSearchField(title);
//    pages.userHomePage.ensurePageLoaded().submitSearchRequest();
// TODO Not implemented yet
    return null;
  }

}
